package com.qpx.jiche.auth.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.qpx.jiche.auth.entity.TUser;
import com.qpx.jiche.auth.mapper.TUserMapper;
import com.qpx.jiche.auth.service.ITUserService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mht
 * @since 2020-10-15
 */
@Service
public class TUserServiceImpl extends ServiceImpl<TUserMapper, TUser> implements ITUserService, UserDetailsService {



    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        Wrapper wrapper = new EntityWrapper();
        wrapper.eq("user_name",s);
        TUser tUser = this.selectOne(wrapper);
        if (tUser == null){
            throw new UsernameNotFoundException("用户名不存在");
        }
        return new User(tUser.getUserName(),tUser.getPassword(), AuthorityUtils.createAuthorityList("admin"));
    }
}
